﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace THenu.Reflection
{
    [Flags]
    public enum FileRight
    {
        None = 0,
        Read = 1,
        Write = 2,
        ReadWrite = 4,
        All = 8
    }
    public class FlagTest
    {
        public static void FlagsAttributeExample()
        {

            for (int i = 0; i < 16; i++)
            {
                Console.WriteLine(((FileRight)i).ToString() + Environment.NewLine);
            }

            FileRight right = FileRight.Read | FileRight.Write;

            if (right.HasFlag(FileRight.Read))
            {
                Console.WriteLine(right.ToString() + " Has " + FileRight.Read.ToString());
            }

            Console.WriteLine("\r\nRemove Write :");
            right = right & (~FileRight.Write);
            Console.WriteLine(right.ToString());

            Console.WriteLine("\r\nAdd Write :");
            right = right | FileRight.Write;
            Console.WriteLine(right.ToString());

            Console.WriteLine("\r\ntrue ^ true\t");
            Console.WriteLine(true ^ true);  // logical exclusive-or
            Console.WriteLine("\r\ntrue ^ false\t");
            Console.WriteLine(true ^ false);  // logical exclusive-or
            Console.WriteLine("\r\n false ^ false\t");
            Console.WriteLine(false ^ false); // logical exclusive-or
            // Bitwise exclusive-or:
            Console.WriteLine(Convert.ToString(0xf8, 2));
            Console.WriteLine(Convert.ToString(0x3f, 2));
            Console.WriteLine("0x{0:x}", 0xf8 ^ 0x3f);
            Console.WriteLine(Convert.ToString(0xf8 ^ 0x3f, 2));

            Console.WriteLine("^ Swap");
            int a = 12, b = 21;
            Console.WriteLine("A : {0}, B : {1}", a, b);
            a = a ^ b;
            b = b ^ a;
            a = a ^ b;

            Console.WriteLine("A : {0}, B : {1}", a, b);

            Console.WriteLine(1 ^ 0);
            Console.WriteLine(0 ^ 1);



        }
    }
}
